package classes{
	import beniAS3Lib.utils.BeniStr;
	
	import classes.vo.VOData;
	
	import flash.filesystem.File;
	import flash.filesystem.FileMode;
	import flash.filesystem.FileStream;
	
	public class CreateVO{
		
		private var _templateStr:String;
		private var _modelLocator:ModelLocator = ModelLocator.item;
		
		
		public function CreateVO(){
			
			initTemplateStr();
			createFiles();
			
		}
		
		
		private function initTemplateStr():void{
			var file:File = File.applicationDirectory.resolvePath('template/#Files/VOFile.as_');
			var fs:FileStream = new FileStream();
			fs.open(file, FileMode.READ);
			_templateStr = fs.readUTFBytes(fs.bytesAvailable);
			_templateStr = UtilFun.getReplaceStr(_templateStr);
			fs.close();
		}
		private function createFiles():void{
			var ary:Array = _modelLocator.voColl.source;
			var item:VOData;
			var content:String;
			var className:String;
			var fileName:String;
			var file:File;
			var fs:FileStream;
			for each (item in ary){
				className = item.name;
				fileName = className + '.as';
				content = BeniStr.multiReplaceByStr(_templateStr, '#ClassName#', className);
				file = new File(_modelLocator.voFolder + fileName);
				fs = new FileStream();
				fs.open(file, FileMode.WRITE);
				fs.writeUTFBytes(content);
				fs.close();
			}
		}
	}
}